package edu.hawaii.myisern.model;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
 * Class to the User.java
 * @author Shaoxuan Zhang
 *
 */
public class TestUser {
  /**
   * Test functions of User.
   */
  @Test public void testUser() {
    String username = "I am not a tester";
    String password = "The password is fake.";
    User testUser1 = new User();
    testUser1.setUsername(username);
    testUser1.setPassword(password);
    User testUser2 = new User(username, "new password");
    assertTrue("2 user has the same name", 
        testUser1.getUsername().equals(testUser2.getUsername()));
    assertFalse("but have different password", 
        testUser1.getPassword().equals(testUser2.getPassword()));
    assertEquals("However, they should be seen as equal", testUser1, testUser2);
    assertEquals("They should have same hashcode", testUser1.hashCode(), testUser2.hashCode());
    testUser2.setUsername("I want a new name");
    assertFalse("Now they are different", testUser1.equals(testUser2));
    assertNotSame("Now they are different", testUser1.hashCode(), testUser2.hashCode());
  }
}
